import pandas as pd
import json
import math

class ExcelData2Json:
    def __init__(self):
        self.data_list = []
    def loadData2Path(self, path):
        ex_data = pd.read_excel(path)
        # 读取excel中表头
        head_list = list(ex_data.columns)
        list_dict = []
        for i in ex_data.values:
            # 使用表头和每行的数据组装json格式数据
            a_line = dict(zip(head_list, i))
            list_dict.append(a_line)
        # 把列表中的数据转为json格式的字符串
        self.date_list = json.dumps(list_dict, ensure_ascii=False)
        return self.date_list

    def getDataList(self):
        return self.date_list

    def formatList(self, arr):
        lists = arr
        for i , v in enumerate(arr) :
            print(v)
            if math.isnan(v):
                lists[i] = ''
        return lists


#print(ExcelData2Json().loadData2Path("./biaozhu.xlsx"))


